<template>
  <div class="body">
    <van-nav-bar
    title="填写订单"
    left-arrow
    @click-left="$router.back()"
    />
    <div class="address" @click="$router.push('/address')" v-if="addresses.address">
      <div class="address-top">
        <div class="address-top1">默认</div>
        <div class="address-top2">学校</div>
        <div class="address-top3">{{ addresses.address.local }}</div>
      </div>
      <div class="address-mid">{{ addresses.address.detailLocal }}</div>
      <div class="address-button">
        <div class="address-button1">{{ addresses.address.user }}</div>
        <div class="address-button2">{{ addresses.address.phone }}</div>
      </div>
    </div>
    <div class="address" v-else >
      <div class="address-else" @click="$router.push('/address')">请选择收货地址</div>
    </div>
    <div class="orders">
      <div class="order" v-for="(item,index) in cartCheckedList" :key="index">
          <img :src="require('../../assets/'+item.imageUrl)" alt="">
          <div class="productInfo">
            <div class="productInfo-top">{{item.description}}</div>
            <div class="productInfo-button">
              <div class="productInfo-button-left">￥{{ item.price }}</div>
              <div class="productInfo-button-right">x<strong>{{ item.quantity}}</strong></div>
            </div>
          </div>
      </div>
    </div>
    <div class="order-information">
      <div class="order-information1">
        <div class="order-information1-left">商品金额</div>
        <div class="order-information1-right">￥{{ selPrice }}</div>
      </div>
      <div class="order-information2">
        <div class="order-information2-left">运费</div>
        <div class="order-information2-right">￥{{ transportPrice }}</div>
      </div>
      <div class="order-information3">
        <div class="order-information3-left">优惠券</div>
        <div class="order-information3-right">无</div>
      </div>
      <div class="order-information4">合计: <span style="color:red">￥{{ totalPrice }}</span></div>
    </div>
    <div class="footer2">
      <div class="footer2-left">￥{{ totalPrice }}</div>
      <div class="footer2-right" @click="$router.push('/myOrder')">提交订单</div>
    </div>
  </div>
</template>
<script>
import { mapGetters, mapState } from 'vuex'
export default {
  name: 'myOrderIndex',
  data () {
    return {
      cartCheckedList: [],
      transportPrice: 0.0, // 运费为商品价格的3%
      totalPrice: 0.0
    }
  },
  computed: {
    ...mapGetters('cart', ['selCartLists', 'selPrice', 'selCount']),
    ...mapState('address', ['addresses'])
  },
  methods: {
    getAddressList () {
      this.$store.dispatch('address/getAddressAction')
    },
    getCartChecked () {
      this.cartCheckedList = this.selCartLists
    },
    getTransportPrice () {
      this.transportPrice = (this.selPrice * 0.003).toFixed(2)
    },
    getTotalPrice () {
      this.totalPrice = Number(this.selPrice) + Number(this.transportPrice)
    }
  },
  created () {
    this.getAddressList()
    this.getCartChecked()
    this.getTransportPrice()
    this.getTotalPrice()
  }

}
</script>
<style>
.body {
  height: auto;
  min-height: 100vh;
  width: 100%;
  background-color: gainsboro;
  display: flex;
  flex-direction: column;
}
.address{
  font-size: 16px;
  color: #333;
  width: 95%;
  height: 140px;
  background: #fff;
  margin: 10px auto;
  border-radius: 3%;
  padding: 10px;
}
.address-top{
  height: 20%;
  width: 100%;
  display: flex;
  font-size:12px;

}
.address-top1{
  height: 100%;
  width: 12%;
  text-align: center;
  padding-top: 4px;
  background-color: red;
  background-size: 100% 80%;
  color: #fff;
  margin-right: 3%;
  border-radius: 7%;
}
.address-top2{
  height: 100%;
  width: 12%;
  text-align: center;
  padding-top: 4px;
  background-color: blue;
  color: #fff;
  margin-right: 3%;
  border-radius: 5%;
}
.address-top3{
  height: 100%;
  width: 70%;
  font-size: 14px;
  padding-top: 2px;
}
.address-mid{
  height: 60%;
  width: 100%;
  padding-top: 5px;
  font-size: 20px;
  font-weight: bold;
  padding-bottom: 5px;
}
.address-button{
  height: 20%;
  width: 100%;
  display: flex;
}
.address-button1{
  height: 100%;
  width: 18%;
  font-size: 14px;

}
.address-button2{
  height: 100%;
  padding-top: 1px;
  width: 82%;
}
.address-else{
  height: 100%;
  width: 100%;
  text-align: center;
  padding-top: 43px;
  font-size: 25px;
  color:red;
}
.orders{
  height: auto;
  min-height: 150px;
  width: 95%;
  background-color: gainsboro;
  margin: 10px auto;
}
.order{
  height: 140px;
  width: 98%;
  border: #333 solid 1px;
  border-radius: 3%;
  background-color: #fff;
  margin: 5px auto;
  padding: 5px;
  display: flex;
}
.order img{
  height: 100%;
  width: 40%;
  border-radius: 8px;
}
.order .productInfo{
  height: 100%;
  width: 60%;
}
.productInfo-top{
  height: 70%;
  width: 100%;
  padding: 5px;
}
.productInfo-button{
  height: 30%;
  width: 100%;
  display: flex;
  padding: 5px;
}
.productInfo-button-left{
  height: 100%;
  width: 50%;
  padding-top: 5px;
}
.productInfo-button-right{
  height: 100%;
  width: 50%;
  padding-top: 5px;
  text-align: right;
}
.order-information{
  height: 150px;
  width: 95%;
  background-color: #fff;
  margin:1px auto;
  border: #333 solid 1px;
  border-radius: 3%;
  padding: 5px;
  margin-bottom: 60px;
}
.order-information1,
.order-information2,
.order-information3{
  height: 25%;
  width: 100%;
  display: flex;
  justify-content: space-between;
}
.order-information4{
  height: 25%;
  width: 100%;
  font-size: 16px;
  text-align: right;
}
.footer2{
  height: 50px;
  width: 100%;
  background-color: #fff;
  position: fixed;
  bottom: 0;
  display: flex;
}
.footer2-left{
  height: 100%;
  width: 50%;
  text-align: center;
  line-height: 50px      ;
  font-size: 25px;
  font-weight: bold;
}
.footer2-right{
  height: 100%;
  width: 50%;
  background-color: red;
  text-align: center;
  padding-top: 10px;
  color: #fff;
}
</style>
